#    This file is part of OpenPolitik.
#
#    OpenPolitik is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    OpenPolitik is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with OpenPolitik.  If not, see <http://www.gnu.org/licenses/>.
import os
import re
import urllib

import session

from google.appengine.api import users
from google.appengine.api import mail
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template

import op_models
import helpers

class ShowUser(webapp.RequestHandler):
	def get(self, email):
		email = urllib.unquote(urllib.unquote(email))
		template_values = helpers.get_liu_stuff(self.request.uri)
		liu = template_values["liu"]

		if liu == None:
			self.redirect(template_values["login_url"])
			return

		user = users.User(email)

		uigs = op_models.UserInGame.all().filter("user = ", user).fetch(10)
		games = [u.game for u in uigs]

		template_values["user"] = user
		template_values["games"] = games
		self.response.out.write(template.render(helpers.get_path("show_user"), template_values))
